#ifndef FTPTHREAD_H
#define FTPTHREAD_H

#include <QThread>
#include <QWaitCondition>
#include <QMutex>
#include <QList>
#include "ftpcurl.h"

namespace Ftp{
    typedef enum {
        eNone,
        eDownload
    }TaskID;
}

class Task : public QObject
{
public:
    Task(Ftp::TaskID tid);
    void setDownLoadData(QString url, QString filePath);
    QString url;
    QString filePath;

    Ftp::TaskID taskID() const;
private:


    Ftp::TaskID tid;
};

class FtpThread : public QThread
{
    Q_OBJECT
public:
    explicit FtpThread(QObject *parent = 0);
    
    void beginThread();
    void endThread();
    void download(QString url, QString filePath);
    void pause();

    typedef enum {
        eWaiteTask,
        eExecTask
    }ThreadState;

signals:
    void TranslateProgress(QString,quint32,quint32,double);
    void TranslateStop(QString, bool);

protected:
    void run();
    void TaskDownLoad(QString url, QString filePath);
private:
    ThreadState state;
    QMutex muxState;
    ThreadState State();
    void setState(ThreadState state);

    QWaitCondition waitTask;
    QMutex muxWait;
    
    volatile bool bQuit;
    QMutex muxQuit;
    bool isQuit();
    void setQuit(bool bQuit);

    QList<Task*> lstTask;
    QMutex muxTaskQueue;
    Task* firstTask();
    void appendTask(Task* task);

    FtpcurlEx ftpEx;
};

#endif // FTPTHREAD_H
